package org.fujay.langchain4jserver.domain.application.vo;

import lombok.Builder;
import org.fujay.langchain4jserver.domain.knowledge.vo.KnowledgeBaseId;
import org.fujay.langchain4jserver.domain.model.vo.ModelId;

import java.io.Serial;
import java.io.Serializable;

/**
 * 应用配置快照值对象 (用于历史记录)
 */
@Builder
public record AppConfigSnapshot(
        ModelId modelId, Boolean useKnowledgeBase, KnowledgeBaseId knowledgeBaseId)
        implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    // 可以添加更多需要记录的配置项，例如检索参数等
    // Map<String, Object> retrievalParameters;

    // 构造函数确保一致性
    public AppConfigSnapshot(
            ModelId modelId, Boolean useKnowledgeBase, KnowledgeBaseId knowledgeBaseId) {
        this.modelId = modelId;
        this.useKnowledgeBase = useKnowledgeBase != null ? useKnowledgeBase : false;
        // 如果不使用知识库，则知识库ID应为null
        this.knowledgeBaseId =
                (this.useKnowledgeBase && knowledgeBaseId != null) ? knowledgeBaseId : null;

        // 验证
        if (this.useKnowledgeBase && this.knowledgeBaseId == null) {
            throw new IllegalArgumentException(
                    "KnowledgeBaseId cannot be null when useKnowledgeBase is true.");
        }
        if (this.modelId == null) {
            throw new IllegalArgumentException("ModelId cannot be null in snapshot.");
        }
    }
}
